package cn.fanqinghong.ymcc.mq.consumer;

import cn.fanqinghong.ymcc.constants.CourseOrderContants;
import cn.fanqinghong.ymcc.dto.KillPreOrderDto;
import cn.fanqinghong.ymcc.service.ICourseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.checkerframework.checker.units.qual.A;
import org.redisson.api.RSemaphore;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * FAN
 * 2022/8/2  18:38
 */
@RocketMQMessageListener(
        consumerGroup = CourseOrderContants.COURSE_ORDER_PRODUCER_GROUP,
        topic = CourseOrderContants.COURSE_ORDER_CONSUMER_DELAY_TOPIC,
        selectorExpression = CourseOrderContants.COURSE_ORDER_CONSUMER_DELAY_TAG,
        messageModel = MessageModel.BROADCASTING
)
@Slf4j
@Component
public class CourseOrderOutTimeConsumer implements RocketMQListener<MessageExt> {


    @Autowired
    private ICourseOrderService courseOrderService;
    @Override
    public void onMessage(MessageExt message) {
        log.info("订单微服务：接收到支付超时消息");
        byte[] body = message.getBody();
        if (body == null || body.length == 0){
            return;
        }
        String orderNo = new String(body, StandardCharsets.UTF_8);
        courseOrderService.cancelOrder(orderNo);
    }
}
